<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Improve HW</title>
  <script type="text/javascript">

	function q1(){
		var a = document.getElementById("q1_1").value;
		var check = true;
		for (var i=2; i<=a-1; i++){
			if (a%i==0){
				check=false;
			}
		}
		if (check){
			document.getElementById("q1").innerHTML= (a +"是素数");
		}else{
			document.getElementById("q1").innerHTML= (a +"不是素数");
		}
	}
	
	
	function q2(){
		var num= document.getElementById("m").value;
		var sum= q2_1(parseInt(num));
		document.getElementById("q2").innerHTML= "第"+num+"月有"+sum+"对兔子";
	}

	function q2_1(i){
		if(i==1){
			return 1;
		}
		if(i==2){
			return 1;
		}
		return q2_1(i-1)+q2_1(i-2);
	}
	
	function q3(){
		var sum=1;
		for(var p=1;p<7;p++){
			sum = (sum+1)*2;
		}
		document.getElementById("q3").innerHTML=("果园里本来有"+sum+"只桃子。");
	}
	
	function q4(){
		var myDate = new Date();
		var year = document.getElementById("year").value;
		var month = document.getElementById("month").value;
		var day = document.getElementById("day").value;
		var firstDay = new Date();
		myDate.setFullYear(year,month-1,day);
		var a,b,c;
		firstDay.setFullYear(year,1,1);
			var count,week;
			var i = 1;
			count = 0;
			while(i<=month){
				if(i==month){
					count=count+ Number(day);
				}else if (i==2){
					if (((year%4==0)&&(year%100!=0))||(year%400==0)){
						count = count +29;
					}else {
						count = count + 28;
					}
				}else if (i==4,6,9,11)
				{
					count = count + 30;
				}else {
					count = count +31;
				}
				i++;
			}
			if(firstDay.getDay()==0){
				if (myDate.getDay()==6){
					week = parseInt((count-(count%7))/7);
				}else {
					week = parseInt((count-((count)%7))/7)+1;
				}
				if (myDate.getDate()<7){
					week=0;
				}else if(myDate.getDate()==7){
					week=1;
				}
				document.getElementById("q4").innerHTML= ("这是"+ year + "年的第"+ (week+1) +"周");
			}else{
				if (myDate.getDay()==6){
					week = parseInt((count-((count-firstDay.getDay())%7))/7);
				}else {
					week = parseInt((count-((count-firstDay.getDay())%7))/7)+1;
				}
				if (myDate.getDate()<7){
					week=0;
				}else if(myDate.getDate()==7){
					week=1;
				}
				document.getElementById("q4").innerHTML= ("这是"+ year + "年的第"+ (week+1) +"周");
			}
	}
	
	function q5(){
		var num = new Array(8);
		/*for(var i=1;i<10;i++){
			for(ii in num){
				if(!num.prototype.in_array(i)){
					
				}
			}
		}*/
		/*Q5:九宫图就是把1~9九个数字填到3×3，使其每一横坚斜之和都相等。用程序完成九宫图各种可能(一共八中可能).*/
		

		document.getElementById("q5").innerHTML="未完成=L=，来年再说。";
	}
  </script>
 </head>
 <body>
	<div id="Q1">
		Q1:输入一数字，判断这个数字是否是素数<br/>
		&nbsp;&nbsp;&nbsp;&nbsp;素数：只能被1和自身整除的数
		<p>
			&nbsp;&nbsp;&nbsp;&nbsp;<span id="q1"></span><br/>
			&nbsp;&nbsp;&nbsp;&nbsp;<input id="number" type="number" maxlength="8"/>
			<button onclick="q1()">submit</button>
		</p>
	</div>
		
	<div id="Q2">	
		！！！Q2:动物界中兔子是一种繁殖是非常快的动物，通常，一对新生兔从他们长大到<br/>
		&nbsp;&nbsp;&nbsp;&nbsp;第三个月的时候就可以生一对小兔子了，并且在今后的每个月都可以生<br/>
		&nbsp;&nbsp;&nbsp;&nbsp;一对小兔子。那么我们假设没有兔子死亡的话，N（3---24）个月后的兔子总对数是多少？<br/>
		<p>
		&nbsp;&nbsp;&nbsp;&nbsp;<span id="q2"></span><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;请输入月份：<input type="text" id="m"/>
		<button onclick="q2();">submit</button>
		</p>
	</div>
		 
	<div id="Q3">	 
		Q3:果园里有一堆桃子，和一只猴子，这只猴子第一天把桃子吃了一半，扔掉了一个坏掉的：<br/>
		&nbsp;&nbsp;&nbsp;&nbsp;第二天又吃了剩下的一半又扔掉了个一个坏掉的；以后每天如此，到第七天就剩一只桃子了。<br/>
		&nbsp;&nbsp;&nbsp;&nbsp;请问最初果园里有多少只桃子？
		<p>
		&nbsp;&nbsp;&nbsp;&nbsp;<span id="q3"></span><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="q3()">submit</button>			
		</p>
	</div>   
		
	<div id="Q4">	
		**Q4:让用户输入年份，月份，日期，输出该天是当年的第几周。<br/>
		<p>
			&nbsp;&nbsp;&nbsp;&nbsp;<span id="q4"></span><br/>
			&nbsp;&nbsp;&nbsp;&nbsp;年：
			<input type="number" style="width:50px;" maxlength="4" id="year"/>
			&nbsp;&nbsp;&nbsp;&nbsp;月：
			<input type="number" style="width:40px;" maxlength="2" id="month"/>
			&nbsp;&nbsp;&nbsp;&nbsp;日：
			<input type="number" style="width:40px;" maxlength="2" id="day"/>
			&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="q4()">submit</button>
		</p>
	</div>
		
	<div id="Q5">	
		?@#!?#?!?Q5:九宫图就是把1~9九个数字填到3×3，使其每一横坚斜之和都相等。用程序完成九宫图各种可能(一共八中可能).<br/>
		<p>
		&nbsp;&nbsp;&nbsp;&nbsp;<span id="q5"></span><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="q5()">submit</button>			
		</p>
	</div>
 </body>